package net.zjitc;

import java.net.*;

/**
 * @author 3505
 * @version 1.0
 * @date 2018/6/27
 */
public class ReceiveTask implements Runnable {
    private int receivePort;
    public ReceiveTask(int receivePort) {
        this.receivePort=receivePort;
    }

    @Override
    public void run() {
        try {
            DatagramSocket ds=new DatagramSocket(receivePort);
            byte[] buff=new byte[1024];
            DatagramPacket dp=new DatagramPacket(buff,buff.length);
            while (true){
                ds.receive(dp);
                String str=new String(dp.getData(),0,dp.getLength());
                System.out.println("收到"+dp.getAddress().getHostAddress()+"--发送的信息--"+str);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
